/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 处理02;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @description 异常处理 throws
 *      方式 throws + 异常类型 写在方法声明处指明可能出现的异常类型
 *      一旦有异常 其后代码不执行
 *      “甩锅”
 * @author 俊昭
 * @date 2022/4/11
*/
public class ThrowsTest {
    @Test
    public void test02() throws IOException{
        test01();
    }

    @Test
    public void test01() throws IOException {// java.io.FileNotFoundException: Hello.txt (系统找不到指定的文件。)
        File file = new File("Hello.txt");
        FileInputStream fis =new FileInputStream(file);// FileNotFoundException

        int data = fis.read();// IOException
        while (data!=-1){
            System.out.print((char) data);
            data= fis.read();// IOException
        }

        fis.close();// IOException
    }
}
